﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>成本核算</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <link href="~/Content/formstyles.css" rel="stylesheet" />
    <script type="text/javascript">
        var _FItemID;
     
        $(function () {   
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "CAIndex", "KeyName": "CAIndex" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) { 
                        var toolbar = getToolBar(data);      //common.js
                         if (data.search) {     //判断是否有浏览权限  
                            $("#ui_costaccount_dg").datagrid({       //初始化datagrid
                                url: "/CostAccount/GetCostAccountEntry?r=" + Math.random(),
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                fitColumns:true,
                                idField: 'ProjectNo',
                                sort: 'ProjectNo',
                                order: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                columns: [[
  
                                                       {
                                                           //width: '100',
                                                           title: '项目编码',
                                                           field: 'ProjectNo' 
                                                       }
                                                       ,
                                                       {
                                                          // width: '200',
                                                           title: '项目名称',
                                                           field: 'ProjectName',
                                                           formatter: function (value, row, index) {
                                                               if (value) {
                                                                   return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                                      }
                                                               }
                                                       },
                                                        {
                                                            //width: '120',
                                                            title: '物料编码',
                                                            field: 'FitemNo' 
                                                        },
                                                        {
                                                            width: '180',
                                                            title: '物料名称',
                                                            field: 'FName',
                                                            formatter: function (value, row, index) {
                                                                if (value) {
                                                                    return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                                }
                                                            }
                                                        },                                                        
                                                        {
                                                            width: '160',
                                                            title: '规格型号',
                                                            field: 'FModel',
                                                            formatter: function (value, row, index) {
                                                                if (value) {
                                                                    return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                                }
                                                            }
                                                        }, 
                                        {
                                            field: 'estCost', title: '预估成本'
                                            //, width: 60
                                        },
                                          {
                                              field: 'stdCost', title: '标准成本'
                                              //, width: 60
                                          },
                                           {
                                               field: 'reaCost', title: '实际成本'
                                               //, width: 60
                                           },
                                            {
                                                width: 60, title: '操作', field: '_operate', formatter:

                                 function (val, row, index) {
                                     var _id = row.FItemID||row.FitemNo;//按项目查询时返回FitemNo，按物料查询返回FitemID,按物料查询ID和No均有，取ID值；
                                     return '<a href="javascript:void(0)" onclick="showBom(' + _id + ')">查看</a>';
                                 }
                                            }
                           
                                ]],                               
                                toolbar: toolbar.length == 0 ? null : toolbar,
                                onSelect: function (rowIndex, rowData) { 
                                },
                                onLoadSuccess: function (data) {//自动隐藏无数据列 
                                }
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
            //回车搜索
            $("#ui_costaccount_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    ui_costaccount_searchdata();
                }
            })
        });
        //显示bom表
        function showBom(FItemID) {
            _FItemID = FItemID;
            $('#cabomtree').treegrid('loadData', { total: 0, rows: [] });
            $('#cabomtree').treegrid('reload', { itemid: FItemID });
            $('#cawin').window('open');
            $('#cawin').window("resize", { top: $(document).scrollTop() + ($(window).height() - 450) * 0.5 });//居中显示
        }
 
        function ui_costaccount_searchdata() {
            $("#ui_costaccount_dg").datagrid('load', {
                ProjectNo: $('#txtProjectNo').val(),
                ItemName: $('#txtItemName').val(),
                ItemModel: $('#txtItemModel').val(), 
            });
            // $("#ui_costaccount_dg").datagrid('clearSelections').datagrid('clearChecked'); 
        }

        function ui_costaccount_cleardata() {
            $('#ui_costaccount_search input').val('');
            $('#ui_costaccount_search select').val('select');
            $('#txtAddBeginDate').datetimebox('setValue', '');
            $('#txtAddEndDate').datetimebox('setValue', '');
            $("#ui_costaccount_dg").datagrid('load', {});//清空条件自动加载数据

            //  $("#ui_costaccount_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
         
        function exportsave() { 
            var url = "/Bom/ExportExcel?r=" + Math.random();
            var data = {
                "FItemID": _FItemID,
                "filetype": "excel",
            };
            download(url, data, 'post');

        }
 
    </script>
</head>
<body>
    <div id="ui_costaccount_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',split:true,border:true,collapsed:false" title="条件搜索" style="height:104px;">
            <div id="ui_costaccount_search">
                <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                    <tr>
                        <th>
                            项目编号：
                        </th>
                        <td>
                            <input name="txtProjectNo" id="txtProjectNo" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            物料名称：
                        </th>
                        <td>
                            <input name="txtItemName" id="txtItemName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>
                        <th>
                            规格型号：
                        </th>
                        <td>
                            <input name="txtItemModel" id="txtItemModel" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        
                        <td colspan="4">
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="ui_costaccount_searchdata();">搜索</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                               onclick="ui_costaccount_cleardata();">清空条件</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center', border:false">
            <table id="ui_costaccount_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
    <div id="cawin" class="easyui-window" title="Bom表" style="width:900px;height:550px"
         data-options="closed:true,iconCls:'icon-save',modal:true">
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="javascript: $('#cabomtree').treegrid('expandAll');">全部展开</a>
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls: 'icon-remove'" onclick="javascript: $('#cabomtree').treegrid('collapseAll');">全部收起</a>
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls: 'icon-save'" onclick="javascript: exportsave();">导出</a>

        <table id="cabomtree" style="width:850px;height:540px" class="easyui-treegrid"
               data-options="
               url:'/Bom/getBomData',
                method: 'get',
                fitColumns:true,
                state:'closed',
                rownumbers: true,
                idField: 'FNumber',
                treeField: 'FNumber'
            ">
            <thead>
                <tr>
                    @*<th data-options="field:'FItemID'" width="160">物料ID</th>
                    <th data-options="field:'FinterID'" width="80" align="right">Bom ID</th>*@

                    <th data-options="field:'FNumber'" width="150">物料代码</th>
                    <th data-options="field:'FName'" width="180">名称</th>
                    <th data-options="field:'FModel'" width="160">规格型号</th>
                    <th data-options="field:'FQty'" width="80">数量</th>
                    <th data-options="field:'itemPrice'" width="80">材料价格</th>
                    <th data-options="field:'worktime'" width="80">工时</th>
                    <th data-options="field:'FGrossWeight'" width="80">净重</th>
                </tr>
            </thead>
        </table>

    </div>
</body>
</html>
